package com.jdcjk.project.account.view;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.jdcjk.Constant;
import com.jdcjk.R;
import com.jdcjk.base.view.BaseActivity;
import com.jdcjk.base.view.FragmentViewClickListener;
import com.jdcjk.project.account.presenter.RegisteredPresenter;

/**
 * Created by Administrator on 2016/12/13 0013.
 * 用户主界面（注册、找回密码）
 */
public class AccountActivity extends BaseActivity<RegisteredPresenter> implements FragmentViewClickListener {
    private final String TAG = AccountActivity.class.getSimpleName();
    private ResetPwdFragment resetPwdFragment;
    private RegisteredFragment registeredFragment;

    @Override
    public int getLayoutId() {
        return R.layout.activity_account;
    }

    @Override
    public void initContentView(Bundle savedInstanceState) {
        String fragmentInfo = getIntent().getStringExtra(Constant.FragmentInfo.fragment);
        switch (fragmentInfo) {
            case "retrieve_pwd":
                //添加找回密码界面
                resetPwdFragment = new ResetPwdFragment();
                resetPwdFragment.setFragmentViewClickListener(this);
                addFragmentContent(resetPwdFragment, R.id.account_fragment_content, 1);
                break;
            case "registered":
                //添加注册界面
                registeredFragment = new RegisteredFragment();
                registeredFragment.setFragmentViewClickListener(this);
                addFragmentContent(registeredFragment, R.id.account_fragment_content, 1);
                break;
        }
    }


    @Override
    public void onFragmentViewClickListener(View v) {
        switch (v.getId()) {
            case R.id.back_btn:
                finish();
                break;
            case R.id.fragment_registered_btn:
                //注册
                registeredFragment.register();
                break;
            case R.id.fragment_cancle_btn:
                //取消
                finish();
                break;
            case R.id.verification_code_tv:
                //获取验证码
                registeredFragment.getVerificationCode();
                break;
            case R.id.fragment_retrieve_pwd_btn:
                //重置密码
                resetPwdFragment.retrievePwd();
                break;
            case R.id.retpwd_verification_code_tv:
                //重置密码时获取验证码
                resetPwdFragment.getVerificationCode();
                break;
            case R.id.registered_address_tv:
                //地址输入框监听，弹出地址选择器
                registeredFragment.choiceAddress();
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
//        if (resultCode == 1) {
//            String result = data.getExtras().getString("result");//得到二维码扫描后后返回的数据
//            registeredFragment.setImeiNumber(result);
//        }
    }
}
